<template>
  <div class="carAppeal_list">
    <c-title :hide="false" :text="'车辆申诉'"></c-title>
    <van-search v-model="keyword" placeholder="请输入手机号搜索" @search="onSearch" />
    <div class="list">
      <template v-if="infoList.length">
        <div class="lis" v-for="item in infoList" :key="item.id">
          <div class="list_top">
            <div class="list_top_l">{{ item.created_at }}</div>
            <div class="list_top_r">{{ item.status_name }}</div>
          </div>
          <div class="leftTXT">手机号：{{ item.mobile }}</div>
          <div class="leftTXT">车牌号：{{ item.license_no }}</div>
          <div class="imgBox">
            <div class="txt">身份证：</div>
            <div class="imgList">
              <template v-if="item.idcard_imgs.length > 0">
                <img :src="imgele" alt="" v-for="(imgele, index) in item.idcard_imgs" :key="index" />
              </template>
            </div>
          </div>
          <div class="imgBox">
            <div class="txt">行驶证：</div>
            <div class="imgList">
              <template v-if="item.driving_permit_imgs.length > 0">
                <img :src="imgele" alt="" v-for="(imgele, index) in item.driving_permit_imgs" :key="index" />
              </template>
            </div>
          </div>
          <div class="reason" v-if="item.reject_msg">驳回原因：{{ item.reject_msg }}</div>
        </div>
      </template>
      <van-empty v-else :image="emptyImg" description="暂无内容" />
    </div>
    <div class="bottom_btn set-pc-style">
      <div class="btn" @click="confirmTap">车辆申诉</div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      keyword: "",
      emptyImg: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/images%2Fcar-manage%2FlistNone%402x.png",
      infoList: [],
      page: 1,
      total_page: 0,
      isLoadMore: true
    };
  },
  activated() {
    this.getData();
  },
  methods: {
    onSearch() {
      this.initGet();
      this.getData();
    },
    initGet() {
      this.page = 1;
      this.total_page = 0;
      this.isLoadMore = true;
      this.infoList = [];
    },
    async getData() {
      let { data, msg, result } = await $http.post("plugin.car-manage.frontend.controllers.appeal.index", { search: { mobile: this.keyword } }, "");
      if (result) {
        if(data.length > 0 || data.data){
          this.infoList = data.data;
          this.total_page = data.last_page;
          this.isLoadMore = true;  
        }
      } else {
        this.$toast(msg);
      }
    },
    confirmTap() {
      this.$router.push(this.fun.getUrl("carAppeal", { source: "1" }));
    },
    async getMoreData() {
      if (!this.isLoadMore) return;
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page += 1;
        let json = {
          search: { mobile: this.keyword },
          page: this.page
        };
        let urlstr = "plugin.car-manage.frontend.controllers.appeal.index";
        $http
          .get(urlstr, json, "加载中")
          .then(res => {
            this.isLoadMore = true;
            if (res.result == 1) {
              this.infoList = this.infoList.concat(res.data.data);
            } else {
              this.page = this.page - 1;
              this.isLoadMore = false;
            }
          })
          .catch(error => {
            console.log(error);
          });
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.carAppeal_list {
  padding-bottom: 5rem;
  .list {
    padding: 0.63rem 0.75rem;
    padding-top: 0;
    box-sizing: border-box;
    .lis {
      background: #ffffff;
      padding: 0.63rem;
      box-sizing: border-box;
      border-radius: 0.5rem;
      margin-top: 0.63rem;
      .leftTXT {
        font-size: 0.88rem;
        line-height: 0.98rem;
        margin-top: 0.94rem;
        text-align: left;
      }
      .imgBox {
        margin-top: 0.94rem;
        .txt {
          font-size: 0.88rem;
          line-height: 0.98rem;
          text-align: left;
        }
        .imgList {
          display: flex;
          flex-wrap: wrap;
          img {
            width: 6.56rem;
            height: 6.56rem;
            border-radius: 0.5rem;
            margin: 0;
            margin-right: 0.5rem;
            margin-top: 0.63rem;
          }
        }
      }
      .reason {
        margin-top: 0.94rem;
        background: #f5f5f5;
        border-radius: 0.5rem;
        padding: 0.66rem 0.63rem;
        box-sizing: border-box;
        font-size: 0.81rem;
        color: #3b3b4a;
        line-height: 0.98rem;
        text-align: left;
      }
      .list_top {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 0.91rem;
        border-bottom: 1px solid #f5f5f5;
        .list_top_l {
          font-weight: 500;
          font-size: 0.88rem;
          flex: 1;
          text-align: left;
        }
        .list_top_r {
          font-size: 0.81rem;
          color: #f15353;
          flex-shrink: 0;
        }
      }
    }
  }
}
.bottom_btn {
  width: 100%;
  position: fixed;
  left: 0;
  bottom: 0;
  background: #ffffff;
  padding: 0.63rem 0.75rem;
  .btn {
    height: 2.5rem;
    background: #f15353;
    border-radius: 1.28rem;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.94rem;
    color: #ffffff;
  }
}
</style>
